package org.jmq.myblog.controller;

import org.jmq.myblog.pojo.User;
import org.jmq.myblog.service.LoginService;
import org.jmq.myblog.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/api")
public class LoginController {

    @Autowired
    private LoginService loginService;

    @PostMapping("/login")
    public ResponseResult login(@RequestBody User user){
        return loginService.login(user.getUsername(),user.getPassword());
    }

    @GetMapping("/logout")
    @PreAuthorize("@check.hasAuthority('admin')")
    public ResponseResult logout(HttpServletRequest request,HttpSession session){
        return loginService.logout(request);
    }

    @RequestMapping("/test")
    public ResponseResult test() {
        return new ResponseResult(200,"success");
    }
}
